TASK_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

include ../config.mk

# Inputs
SRC := $(TASK_DIR)/src/prepare_data_and_covs_for_regressions.R
COVARIATE_SETS_CONFIG_FILE := $(TASK_DIR)/../run_regressions/hand/covariate_sets.yaml
REG_SCRIPT := $(TASK_DIR)/src/run_stata_dosage_model.do
STATA_FNS := $(TASK_DIR)/src/estrat_dose.do

# One of the outputs
PARAM_FILE := $(OUT_DIR)/load_parameters.do
XSECTION_ANALYSIS_FILE_CSV := $(OUT_DIR)/readi_outcomes_roster_up_to_date.csv
OUT_FILE := $(OUT_DIR)/dosage_heterogeneity.dta


$(PARAM_FILE): $(SRC) $(REG_SCRIPT) $(PROJECT_CONFIG) $(COVARIATE_SETS_CONFIG_FILE) $(XSECTION_ANALYSIS_FILE)
	@mkdir -p $(OUT_DIR)
	@$(R_script) $(SRC) \
		--PROJECT_CONFIG=$(PROJECT_CONFIG) \
		--COVARIATE_SETS_CONFIG_FILE=$(COVARIATE_SETS_CONFIG_FILE) \
		--XSECTION_ANALYSIS_FILE=$(XSECTION_ANALYSIS_FILE) \
		--XSECTION_ANALYSIS_FILE_CSV=$(XSECTION_ANALYSIS_FILE_CSV) \
		--PARAM_FILE=$(PARAM_FILE)

$(OUT_FILE): $(REG_SCRIPT) $(PARAM_FILE) $(XSECTION_ANALYSIS_FILE_CSV)
	@mkdir -p $(OUT_DIR)
	stata -b do $(REG_SCRIPT) $(PARAM_FILE) $(XSECTION_ANALYSIS_FILE_CSV) $(STATA_FNS) $(OUT_FILE) $(OUT_DIR)

.PHONY: all clean
.DEFAULT_GOAL=all

all: $(OUT_FILE)

clean:
	rm -rf $(OUT_DIR)


